package com.seari.custody.component;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import com.google.common.collect.Maps;
import com.seari.custody.bean.Meeting;
import com.seari.custody.bean.Message;
import com.seari.custody.bean.User;
import com.seari.custody.controller.WebsocketController;
import com.seari.custody.enums.InviteLinkType;
import com.seari.custody.enums.MeetingType;
import com.seari.custody.exception.BIZException;
import com.seari.custody.service.MessageService;
import com.seari.custody.service.UserService;
import com.seari.custody.util.EncryptUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class MessagePush {
    @Autowired
    private WeChatMessagePush weChatMessagePush;
    @Autowired
    private MessageService messageService;


    public void pushMessage(Message message) {
        try {

            //保存消息到库并推送给在线用户
            messageService.saveMessage(message);
            WebsocketController.onlinePush(message);

            ThreadUtil.execAsync(() -> weChatMessagePush.pushMessage(message.getContent(), Maps.newConcurrentMap()));

        } catch (Exception e) {
            log.error("发送通知失败:" + message.toString(), e);
        }

    }

}
